package com.myapplication.ui.listfragment.shoplistactivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.myapplication.R;
import com.myapplication.bean.ShopListBean;
import com.myapplication.config.HUrlConfig;
import com.myapplication.ui.listfragment.shoplistactivity.pinglun.CommentActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by My on 2016/10/15.
 */
public class ShopListActivity extends AppCompatActivity implements Contract_ShopList.View {
    private List<ShopListBean.DataBean.ItemsBean> shoplistbean=new ArrayList<>();
    private TextView tv_list_comment,tv_list_time,tv_list_title,tv_shoplist_nickname,tv_pl_count;
    private ImageView iv_shoplist_pl;
    private Contract_ShopList.Presenter mPresenter;
    private Map<String,String> params=new HashMap<>();
    private ShopLvFragmentAdapter adapter;
    private ListView lv_list_gwqd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        mPresenter=new Presenter_ShopList(this);
        params.put(HUrlConfig.key.APP_VERSION,HUrlConfig.DefaultValue.APP_VERSION);
        params.put(HUrlConfig.key.PLATFORM,HUrlConfig.DefaultValue.PLATFORM);

//        Log.i("TAG", "onCreate1111111: "+params);
        tv_list_comment= (TextView) findViewById(R.id.tv_list_comment);
        tv_list_time= (TextView) findViewById(R.id.tv_list_time);
        tv_list_title= (TextView) findViewById(R.id.tv_list_title);
        tv_shoplist_nickname= (TextView) findViewById(R.id.tv_shoplist_nickname);
        tv_pl_count= (TextView) findViewById(R.id.tv_pl_count);
        lv_list_gwqd= (ListView) findViewById(R.id.lv_list_gwqd);
        iv_shoplist_pl= (ImageView) findViewById(R.id.iv_shoplist_pl);

        Intent intent=getIntent();
        String nickname=intent.getStringExtra("nickname");
        String comment=intent.getStringExtra("comment");
        int comments_count=intent.getIntExtra("comments_count",0);
        final int list_id=intent.getIntExtra("list_id",0);
        //deals/goods_list/1097.json?
        String type="deals/goods_list/"+list_id+".json?";
        String title=intent.getStringExtra("title");
        mPresenter.GetData(type,params);
        tv_list_comment.setText(comment);
        tv_shoplist_nickname.setText(nickname);
        tv_pl_count.setText(comments_count+"");
        tv_list_title.setText(title);
        iv_shoplist_pl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(ShopListActivity.this, CommentActivity.class);
                intent.putExtra("list_id",list_id);
                startActivity(intent);
            }
        });
    }

    public void click(View view) {
        switch (view.getId()){
            case R.id.iv_shoplist_back:
                finish();
                break;
//            case R.id.iv_shoplist_pl:
//                Intent intent=new Intent(ShopListActivity.this, CommentActivity.class);
//                intent.putExtra("list_id",shoplistbean.get())
//                break;
        }
    }

    @Override
    public void onGetDataSuccess(final List<ShopListBean.DataBean.ItemsBean> shopListItemBean) {
        Log.i("TAG", "onGetDataSuccess: "+shopListItemBean.size());
        adapter=new ShopLvFragmentAdapter(ShopListActivity.this,shopListItemBean);
        lv_list_gwqd.setAdapter(adapter);

    }

    @Override
    public void onGetDataFail(String error) {

    }
}
